<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="static/bootstrap/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/bootstrap/js/bootstrap.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript" src="static/excel/datagrid-export.js"></script>
<title>项目工资</title>

</head>

<body>
<div class="content-container" data-options="region:'center'">
<div class="panel-header"><div class="panel-title">项目工资列表</div></div>
		<table id="pro_table" class="easyui-datagrid" style="height: 100%">
		</table>
	
	<div id="pro_tb">
		<div class="search-container">
			<div class="search-input">
				项目：
				<input style="width: 200px;" id="projectitemid" name="projectitemid" class="easyui-combobox"
					editable="false"
					data-options="
							    valueField: 'id',
							    textField: 'name',
							    url: 'projectitemuserlist.do',
							    onLoadSuccess : function(data){ 
								   	if(data.length>0){
								   		$('#projectitemid').combobox('setValue',data[0].id);
							    	}
							    },onSelect: function(rec){
						    		projectitemid = rec.id;
							    	if(rec.projectitemchilds.length>0){
										var url = 'projectitemchildlist?status=2&&projectitemid=' + rec.id;
										$('#projectitemchildid').combobox('reload', url);
										document.getElementById('div1').style.display = '';
							    	}else{
							    		projectitemchildid = 0;
										$('#projectitemchildid').combobox('clear');
										document.getElementById('div1').style.display = 'none';
							    		loadData();
							    	}
							    },panelHeight: 'auto'">
			</div>
			<div id="div1" style="display: none;" class="search-input">
				子项目：
				<input style="width: 200px;" id="projectitemchildid" name="projectitemchildid" class="easyui-combobox"
					editable="false"
					data-options="
							    valueField: 'id',
							    textField: 'name',
							    loadFilter: function (data) {
							        var obj = {};
							        obj.id = '';
							        obj.name = '全部';
							        data.splice(0, 0, obj);
							        return data;
							    },
							    onSelect: function(rec){
							    	projectitemchildid = rec.id;
								    	loadData();
							    },panelHeight: 'auto'">
			</div>
			<div class="search-input">
				姓名：
				<input id="name" class="easyui-textbox" />
			</div>
			<div class="search-input">
				工号：
				<input id="jobno" class="easyui-textbox" />
			</div>
			<div class="search-input">
				<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="search">搜索</a>
			</div>
			<div class="search-input">
        		<a href="javascript:;" class="easyui-linkbutton" onclick="Export();">导出Excel</a>
			</div>
		</div>
	</div>
</div>
</body>
<script>
	var currentPro;
	var projectitemid = "";
	var projectitemchildid = "";
	var jobno = "";
	var name = "";
	var projectitemname;
	
	function Export(){　　　　
		$('#pro_table').datagrid('toExcel', {
		    filename: '项目工资-'+formatDate(new Date())+'.xls',
		    worksheet: 'Worksheet'
		});
	}
	
	$("#search").click(function() {
		projectitemid = $("#projectitemid").combobox('getValue');
		projectitemchildid = $("#projectitemchildid").combobox('getValue');
		jobno = $("#jobno").textbox('getValue');
		name = $("#name").textbox('getValue');
		loadData();
	});
	function loadData() {
		if (projectitemchildid > 0){
			$('#pro_table').datagrid({
				rownumbers : true,
				singleSelect : true,
				pagination : true,
				fitColumns : false,
				border : false,
				striped : true,
				toolbar : '#pro_tb',
				url : "jobbers.do",
				method : 'get',
				queryParams : {
					projectitemchildid : projectitemchildid,
					jobno : jobno,
					name : name
				},
				onSelect : function(index,row) {
					currentPro = row;
				},
				onDblClickRow : function(index,row) {
					currentPro = row;
					updatepro();
				},
				columns : [ [ {
					field : 'username',
					title : '姓名',
					width : ''
				},{
					field : 'date',
					title : '施工日期',
					width : '',
					formatter : formatDate
				},{
					field : 'departmentname',
					title : '部门名称',
					width : ''
				},{
					field : 'cnt',
					title : '工日',
					width : ''
				},{
					field : 'salary',
					title : '日薪(元)',
					width : ''
				},{
					field : 'money',
					title : '金额(元)',
					width : ''
				} ] ]
			});
		}else{
			$('#pro_table').datagrid({
				rownumbers : true,
				singleSelect : true,
				pagination : true,
				fitColumns : false,
				border : false,
				striped : true,
				toolbar : '#pro_tb',
				url : "jobbers.do",
				method : 'get',
				queryParams : {
					projectitemid : projectitemid,
					jobno : jobno,
					name : name
				},
				onSelect : function(index,row) {
					currentPro = row;
				},
				onDblClickRow : function(index,row) {
					currentPro = row;
					updatepro();
				},
				columns : [ [ {
					field : 'username',
					title : '姓名',
					width : ''
				},{
					field : 'date',
					title : '施工日期',
					width : ''
				},{
					field : 'departmentname',
					title : '部门名称',
					width : ''
				},{
					field : 'cnt',
					title : '工日',
					width : ''
				},{
					field : 'salary',
					title : '日薪(元)',
					width : ''
				},{
					field : 'money',
					title : '金额(元)',
					width : ''
				} ] ]
			});
		}
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
</script>

</html>